#coding=utf-8

import logging
import wsgiref.handlers

from google.appengine.ext import webapp

import app
from app.dispatcher import *
from app import router
from app.controllers import *


def initRoutes():
    r = router.Router()
    r.connect('/entries/',                  controller = EntryController)
    r.connect('/tags/:tag_key_name/entries',    controller = EntryController)
    r.connect('/resources/',                controller = ResourceController)
    r.connect('/tags/:tag_key_name/resources',  controller = ResourceController)
    r.connect('/entrytags/',                controller = EntryTagController)
    r.connect('/resourcetags/',             controller = ResTagController)
    r.connect('/projects/',                 controller = ProjectController)
    r.connect('/admin/',                    controller = AdminController)
        
def main():
    logging.getLogger().setLevel(logging.DEBUG)
    
    config = app.Config()
    config.template_dir = os.path.join(os.path.dirname(__file__), 'templates')

    initRoutes()
    
    application = webapp.WSGIApplication([(r'.*', RestHandler)], debug=True)
    wsgiref.handlers.CGIHandler().run(application)

if __name__ == '__main__':
    main()
